<!DOCTYPE html>
<html>

<head>
    <title>
        <%- news_result.title %>
    </title>
    <link rel="stylesheet" href="/stylesheets/news_details.css">
    <%- include bootstrap %>
</head>

<body>
    <%- include("header",{title:"news_details"}) %>
    <div class="container container-fluid">
        <div class="row">
            <div class="col-sm-10 col-xs-10 col-sm-offset-1 col-xs-offset-1">
                <h2 class="h1 title" style="font-weight: 900;">
                    <%- news_result.title %>
                </h2>
                <p style="color:#b4b4b4;" class="h3">
                    <%- news_result.ptime %> &nbsp;&nbsp;&nbsp;娱乐新闻网
                </p>
                <div class="col-sm-12 col-xs-12" style="margin-top: 50px;">
                    <img class="col-sm-12 col-xs-12" src="<%- news_result.imgsrc %>" alt="">
                </div>
                <div class="col-sm-12 col-xs-12" style="margin-top: 30px;">
                    <% if(news_user_type === "责任编辑"){ %>
                    <textarea class="col-sm-12 col-xs-12 write_comment" placeholder=""
                        style="margin-top: 15px;height: 400px;" id="comments">
                    <% if(edit_result.length !== 0){ %>
                        <%- edit_result[0].content_edit %>
                    <% } %>
                    </textarea>
                    <button class="btn btn-primary pull-right" style="margin-top: 15px;"
                        onclick="submit_edit('<%- _id %>','<%- db_name %>')">发表</button>
                    <% }else{ %>
                    <div class="col-sm-12 col-xs-12 write_comment" style="margin-top: 15px;">
                        <% if(edit_result.length !== 0){ %>
                        <%- edit_result[0].content_edit %>
                        <% } %>
                    </div>
                    <%}%>
                </div>
            </div>
        </div>
        <div class="row" style="margin-top: 50px;">
            <div class="col-sm-10 col-xs-10 col-sm-offset-1 col-xs-offset-1">
                <ul class="list-group col-sm-12 col-xs-12">
                    <% if(comments_result.length !== 0){ %>
                    <li class="list-group-item list-group-item-success h3 cl">
                        <span class="h3">最新跟帖</span>
                        <a href="/comments/comments?db_name=<%- db_name %>&_id=<%- _id %>" class="text-info pull-right"
                            style="font-size: 16px;cursor: pointer;">发帖</a>
                    </li>
                    <% comments_result.map((item)=>{ %>
                    <li class="list-group-item list-group-item-success">
                        <div>
                            <span class="text-danger h4">
                                评论人：
                                <%- item.username %>
                            </span>
                        </div>
                        <div style="margin-top: 10px;font-size: 16px;">
                            <h4>评论内容：</h4>
                            <div class="text-warning">
                                <%- item.content %>
                            </div>
                        </div>
                        <div><span class="text-info">
                                评论时间：
                                <%- item.insert_time %>
                            </span>
                        </div>
                        <% if(news_user_type === "责任编辑"){ %>
                        <div class="cl">
                            <button class="btn btn-danger pull-right" data-toggle="modal" data-target="#remove_modal"
                                onclick='setId("<%- item._id %>")'>删除</button>
                        </div>
                        <% } %>
                    </li>
                    <% }); %>
                    <li class="list-group-item list-group-item-info">
                        <nav aria-label="Page navigation" class="cl" style="text-align: center">
                            <div style="display: inline-block">
                                <ul class="pagination">
                                    <li>
                                        <a href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- pageNo>1 ? pageNo-1:1 %>"
                                            aria-label="Previous">
                                            <span aria-hidden="true">&laquo;</span>
                                        </a>
                                    </li>
                                    <%    if(pageNo===(totalPage-1)&&totalPage>=5){   %>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- totalPage-4 %>">
                                            <%- totalPage-4 %>
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo===totalPage&&totalPage>=5){   %>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- totalPage-4 %>">
                                            <%- totalPage-4 %>
                                        </a>
                                    </li>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- totalPage-3 %>">
                                            <%- totalPage-3 %>
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo===totalPage&&totalPage===4){   %>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- totalPage-3 %>">
                                            <%- totalPage-3 %>
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo>2){   %>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- pageNo -2 %>">
                                            <%- pageNo-2 %>
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo>1){   %>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- pageNo-1 %>">
                                            <%- pageNo-1 %>
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <li class="active">
                                        <a href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- pageNo %>">
                                            <%- pageNo %>
                                        </a>
                                    </li>
                                    <%    if(pageNo<=totalPage-1){   %>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- pageNo+1 %>">
                                            <%- pageNo+1 %>
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo<=totalPage-2){   %>
                                    <li>
                                        <a
                                            href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- pageNo+2 %>">
                                            <%- pageNo +2  %>
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo===1&&totalPage===4){   %>
                                    <li>
                                        <a href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=4">
                                            4
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo===1&&totalPage>=5){   %>
                                    <li>
                                        <a href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=4">
                                            4
                                        </a>
                                    </li>
                                    <li>
                                        <a href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=5">
                                            5
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <%    if(pageNo===2&&totalPage>=5){   %>
                                    <li>
                                        <a href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=5">
                                            5
                                        </a>
                                    </li>
                                    <%    }   %>
                                    <li>
                                        <a href="/details/?db_name=<%- db_name %>&_id=<%- _id %>&pageNo=<%- pageNo<totalPage ? pageNo+1:totalPage %>"
                                            aria-label="Next">
                                            <span aria-hidden="true">&raquo;</span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </nav>
                    </li>
                    <li class="list-group-item list-group-item-info">
                        <p class="h4 text-danger">
                            第
                            <%- pageNo %> 页 / 共
                            <%- totalPage%> 页
                            总
                            <%- count %> 条
                        </p>
                    </li>
                    <% }else{ %>
                    <li class="list-group-item list-group-item-success h3 cl">
                        <a href="/comments/comments?db_name=<%- db_name %>&_id=<%- _id %>" class="text-info pull-right"
                            style="font-size: 16px;cursor: pointer;">发帖</a>
                    </li>
                    <li class="list-group-item list-group-item-danger h3">
                        暂无评论
                    </li>
                    <% } %>
                    </ul>
                </div>
            </div>
        </div>

        <div class="modal fade" tabindex="-1" role="dialog" id="remove_modal">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <p class="text-danger">是否删除该评论？</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary"
                            onclick="remove('<%- db_name %>','<%- _id %>')">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <%- include("footer") %>
</body>

<script>
    function setId(id) {
        setCookie("remove_id", id);
    }

    function remove(db_name, _id) {
        location.href = `/remove_edit?db_name=${db_name}&_id=${_id}`;
    }

    function submit_edit(_id, db_name) {
        var content = $(".write_comment").val();
        setCookie("content_edit", content);
        location.href = `/edit/submit?_id=${_id}&db_name=${db_name}`;
    }

    // $("#content").xheditor();  // 富文本编辑框 实例化 
    $(pageInit);
    //  comment.ejs  /comment/index
    function pageInit() {
        $.extend(XHEDITOR.settings, {
            shortcuts: {
                "ctrl+enter": submitForm
            }
        });
        // $("#ele").xheditor();
        $("#comments").xheditor({ //初始化 富文件编辑框
            html5Upload: false,
            upMultiple: "1",

            upLinkRrl: "upload.html",
            upLinkExt: "zip,rar,txt",

            upImgUrl: "/comments/uploadImg", // 图片上传的服务器  
            upImgExt: "jpg,jpeg,gif,png",

            upFlashUrl: "upload.php",
            upFlashExt: "swf",

            upMediaUrl: "upload.php",
            upMediaExt: "wmv,avi,wma,mp3,mid"

        });
    };

    function insertUpload(arrMsg) {
        var i, msg;
        for (var i = 0; i < arrMsg.length; i++) {
            msg = arrMsg[i];
            $("#uploadList").append('<option value="' + msg.id + '">' + msg.localname + '</option>')
        }
    };

    function submitForm() {
        $("#frmDemo").submit();
    }
</script>

</html>